<?php

//登陆注册控制器
class LoginController extends Controller{
	  private $model;
	  public function __init(){
	  	$this->model=K('Login');
	  }
	  //注册页
	  public function index(){
	  	
	  	if(IS_POST){
	  		if(!$this->model->zhuce()){
	  			$this->error($this->model->error);
	  		}
			$this->success('注册成功',U('Index/Index/index'));
	  	}
	  	$this->display();
	  }
	  
	  //登陆页
	  public function denglu(){
	  	if(IS_POST){
	  		if(!$userInfo=$this->model->denglu()){
	  			$this->error($this->model->error);
	  		}
			//存入SESSION
			$_SESSION['uid'] = $userInfo['uid'];
			$_SESSION['nicname'] = $userInfo['nicname'];
			$_SESSION['hearimg'] = $userInfo['hearimg'];
			$this->success('登陆成功',U('Index/Index/index'));
	  	}
	  	$this->display();
	  }
	  
	  //验证码
	  public function code(){
	  	 $code = new Code();
		 $code->show();
	  }
	  
	  public function ajaxCheck(){
	  	if(!IS_AJAX) $this->error('非法请求');
		//电子邮箱
		$username = Q('post.username');
		if($this->model->where("username='{$username}'")->find()){
			$this->ajax(array('message'=>'用户名已存在','status'=>false));		
		}else{
			$this->ajax(array('message'=>'可以注册','status'=>true));
		}
	  }
	  
	  public function out(){
	  	session(null);
		$this->success('退出成功',U('Index/Index/index'));
	  }
	  
	  
}



?>